<template>
    <div class="accounting">
        <div class="breadcrumb">
            位置：首页<span>></span>税收法规库<span>></span>{{ getType }}
        </div>

        <div class="title">
            {{ infoData.title }}
        </div>

        <div class="info">
            <div class="info-item">
                <div class="label">发文字号：</div>
                {{ infoData.push_number }}
            </div>
            <div class="info-item">
                <div class="label">发文机关：</div>
                {{ infoData.push_department }}
            </div>
            <div class="info-item">
                <div class="label">发文日期：</div>
                {{ infoData.push_date }}
            </div>
            <div class="info-item">
                <div class="label">效力注释：</div>
                {{ infoData.active_info }}
            </div>
        </div>

        <div v-show="infoData.notice" class="notice">
            <div class="notice-title">小竹提示</div>
            {{ infoData.notice }}
        </div>

        <div
            class="info_content"
            v-html="infoData.info_content"
            @click="imageEnlargement"
        ></div>
        <div style="height: 4.125rem"></div>
        <div class="shoucang">
            <div
                class="but"
                :class="{ 'but-active': infoData.is_collect }"
                @click="setCollection"
            >
                <van-icon
                    v-if="!infoData.is_collect"
                    name="like-o"
                    class="icon"
                    size="1rem"
                />
                <van-icon
                    v-else
                    name="like"
                    color="#FF9B21"
                    class="icon"
                    size="1rem"
                />
                {{ !infoData.is_collect ? "收藏文章" : "已收藏" }}
            </div>
        </div>
    </div>
</template>

<script>
import { mapMutations, mapState } from "vuex";
import { ImagePreview } from "vant";
import {
    getPolicyInfo,
    setPolicyCollect,
    getPolicyPcCate,
} from "@/assets/api/regulationsApi.js";
import { getanalysedata2 } from "@/assets/api/indexApi";
import { recommend_policy } from "@/assets/api/quizData";

import {
    goTop,
    goTopSmooth,
    wrapText,
    getArr_objKey,
    replaceurl,
    getText,
} from "@/assets/utils/utils.js";

import moment from "moment";
import { Toast } from 'vant';
export default {
    components: {},
    async asyncData({ params }) {
        let data = {
            info_content: "",
            infoData: null,
            id: 0,
            mateInfo: {
                title: "税收法规库",
                keywords: "",
                description: "",
            },
            jsonld: {
                "@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
                "@id": "https://www.xzcs2022.com/ssfgk/",
                images: [""],
                title: "",
                description: "",
                pubDate: "",
                upDate: "",
            },
            typePath: "index",
        };

        data.id = parseInt(params.id.replace(".html", ""));
        data.jsonld["@id"] += params.id;

        const res = await getPolicyInfo({
            id: data.id,
        });

        if (res.code == 1) {
            data.infoData = res.data;
            data.info_content = replaceurl(
                res.data.info_content,
                res.data.title
            );
            data.mateInfo.title = data.infoData.title;

            let abstract = data.infoData.abstract;
            if (!data.infoData.abstract) {
                abstract = getText(data.infoData.info_content, 90);
            }
            data.mateInfo.description = abstract;

            data.jsonld.title = data.infoData.title;
            data.jsonld.description = abstract;
            data.jsonld.pubDate = data.jsonld.upDate = moment(
                data.infoData.createtime * 1000
            ).format("YYYY-MM-DD");
        }

        return data;
    },
    layout: "home",
    head() {
        return {
            script: [
                {
                    type: "application/ld+json",
                    innerHTML: JSON.stringify(this.jsonld),
                },
            ],
            __dangerouslyDisableSanitizers: ["script"],
            title: this.mateInfo.title + "-【小竹财税平台】",
            meta: [
                {
                    hid: "description",
                    name: "description",
                    content: this.mateInfo.description,
                },
                {
                    hid: "keywords",
                    name: "keywords",
                    content: this.mateInfo.keywords,
                },
            ],
        };
    },
    data() {
        return {
            tabsIndex: 0,
            tabsTwoIndex: 0,

            fontSizeList: ["font-small", "font-medium", "font-large"],
            fontSizeIndex: 1,

            previewList: [""],

            seekInput: "",
            questionsInfo: {},

            loading: false,

            showNoLogin: false,
        };
    },
    created() {},
    mounted() {
        console.log(this.infoData);

        this.$nextTick(() => {
            this.getData();
            goTopSmooth()
            getanalysedata2({
                m_id: 2,
                type: 1,
                code: "PD12",
                describe: this.infoData.title,
            });
        });
    },
    computed: {
        ...mapState("regulations", {
            tabsList: (state) => state.TTabsList,
        }),
        
        getType: function () {
            if (this.infoData) {
                let text = "";
                let policy_cate_list =
                    this.infoData.policy_cate_id.split(",")[0];
                if (this.infoData.code == 1) {
                    text = "中央法规";
                    this.typePath = "zyfg";
                }
                if (this.infoData.code == 2) {
                    text = "国际跨界税收";
                    this.typePath = "gjkjss";
                } else if (this.infoData.is_fatiao == 1) {
                    text = "法规法条";
                    this.typePath = "fgft";
                } else if (policy_cate_list == "28") {
                    text = "外汇文件";
                    this.typePath = "whwj";
                } else if (policy_cate_list == "27") {
                    text = "海关综合文件";
                    this.typePath = "hgzhwj";
                } else if (policy_cate_list == "32") {
                    text = "12366热点回答";
                    this.typePath = "12366rdwd";
                } else if (policy_cate_list == "30") {
                    text = "政府补助";
                    this.typePath = "zfbz";
                } else if (this.infoData.code != 1) {
                    text = "地方法规";
                    this.typePath = "dfff";
                }
                return text;
            } else return "";
        },
    },
    methods: {
        ...mapMutations("common", ["setmenuIndex", "getUserInfo2"]),

        async getData() {
            try {
                // this.loading = true;
                const res = await getPolicyInfo({
                    id: this.id,
                });
                // this.loading = false;

                if (res.code == 1) {
                    this.infoData = res.data;
                    this.info_content = res.data.info_content;
                    this.mateInfo.title = this.infoData.title;
                    this.mateInfo.description = this.infoData.abstract;
                } else if (res.code == -100) {
                    this.$alert(
                        `<div style='text-align: left'>今日免费次数已用完，请您充值成为会员，以享受更多精彩的功能和服务。</div>`,
                        "温馨提示",
                        {
                            customClass: "vip-message-box",
                            dangerouslyUseHTMLString: true,
                            showClose: false,
                            closeOnClickModal: false,
                            confirmButtonText: "加入会员",
                            callback: (action) => {
                                this.$router.push({
                                    path: "/user/myvip",
                                });
                            },
                        }
                    );
                    this.showNoLogin = true;
                }
            } catch (error) {
                this.loading = false;
            }
        },

        getMetaInfo() {
            if (this.$route.params.type == "index") {
                this.mateInfo.title = "小竹税收法规库-财税法规库";
                this.mateInfo.keywords = "小竹税收法规库,小竹财税法规库";
                this.mateInfo.description =
                    "小竹税收法规库汇集了各种税收政策和地方财税法规，包括但不限于增值税、企业所得税、个人所得税、印花税和土地增值税及相关的税收解读说明和操作指南。";
            } else if (this.$route.params.type == "zyfg") {
                this.mateInfo.title = "中央税收法规";
                this.mateInfo.keywords = "中央税收法规";
                this.mateInfo.description =
                    "小竹财税中央税收法规版块，汇集众多中央税收法规政策。实时更新中央颁布的税收条例及税收相关规定，帮助企业及从业人员深入了解税收法规，并积极响应最新税收政策的宣传与发布。";
            } else if (this.$route.params.type == "yhzz") {
                this.mateInfo.title = "税收优惠政策";
                this.mateInfo.keywords = "税收优惠政策";
                this.mateInfo.description =
                    "小竹财税税收优惠政策版块，汇集众多税收优惠政策。实时更新税收优惠政策条例及税收相关优惠规定出台，并积极响应税收优惠政策的发布与实施。";
            } else if (this.$route.params.type == "dfff") {
                this.mateInfo.title = "地方税收法规";
                this.mateInfo.keywords = "地方税收法规";
                this.mateInfo.description =
                    "小竹财税地方税收法规版块，汇集众多税地方税收法规政策，实时更新地方税收法规条例及相关地方税收法规优惠政策出台，并积极推动地方税收法规宣传与发布。";
            } else if (this.$route.params.type == "hgzhwj") {
                this.mateInfo.title = "海关综合文件税收法规";
                this.mateInfo.keywords = "海关综合文件税收法规";
                this.mateInfo.description =
                    "小竹财税海关综合文件税收法规版块，汇集众多海关综合文件税收法规，实时更海关综合文件税收法规条例及相关海关综合文件税收法规政策出台，并积极推动海关综合文件税收法规宣传与发布。";
            } else if (this.$route.params.type == "gjkjss") {
                this.mateInfo.title = "国际跨境税收法规";
                this.mateInfo.keywords = "国际跨境税收法规";
                this.mateInfo.description =
                    "小竹财税国际跨境税收法规版块，汇集众多国际跨境税收法规。实时更新国际跨境税收条例及相关的国际跨境税收政策出台，并积极推动国际跨境税收政策宣传与发布。";
            } else if (this.$route.params.type == "whwj") {
                this.mateInfo.title = "外汇文件税收法规";
                this.mateInfo.keywords = "外汇文件税收法规";
                this.mateInfo.description =
                    "小竹财税外汇文件税收法规板块，汇集众多外汇文件税收法规。实时更新外汇文件税收法规条例及相关的外汇文件税收法规政策出台，并积极推动外汇文件税收法规宣传与发布。";
            } else if (this.$route.params.type == "12366rdwd") {
                this.mateInfo.title = "12366税收热点问答";
                this.mateInfo.keywords = "12366税收热点问答";
                this.mateInfo.description =
                    "小竹财税12366税收热点问答版块，汇集众多12366税收热点问答。实时更新12366税收热点问答及相关的12366税收热点问答政策出台，并积极推动外汇文件税收法规宣传与发布。";
            } else if (this.$route.params.type == "zfbz") {
                this.mateInfo.title = "政府补助税收法规";
                this.mateInfo.keywords = "政府补助税收法规";
                this.mateInfo.description =
                    "小竹财税政府补助税收法规版块，汇集众多政府补助税收法规。实时更新政府补助税收法规及相关政府补助税收法规政策出台，并积极推动政府补助税收法规宣传与发布。";
            } else if (this.$route.params.type == "fgft") {
                this.mateInfo.title = "税收法规法条";
                this.mateInfo.keywords = "税收法规法条";
                this.mateInfo.description =
                    "小竹财税税收法规法条版块，汇集众多多税收法规法条。实时更新税收法规法条及相关税收法规法条政策出台，并积极推动税收法规法条宣传与发布。";
            }
        },

        // 点击富文本
        imageEnlargement(e) {
            if (e.target.nodeName == "IMG") {
                ImagePreview({
                    images: [e.target.currentSrc],
                    closeable: true,
                });
            }
        },

        // 点击收藏
        async setCollection() {
            const res = await setPolicyCollect({
                id: this.id,
            });
            if (res.code == 1) {
                this.infoData.is_collect == 0
                    ? (this.infoData.is_collect = 1)
                    : (this.infoData.is_collect = 0);
                if (this.infoData.is_collect == 1) {
                    Toast('收藏成功');
                } else {
                    Toast('取消收藏');
                }
            }
        },

        keywordRed() {
            this.seekInput = this.seekInput.replace(/\s/g, "");
            if (!this.seekInput) return;
            let regex = /^[A-Za-z]+$/;
            if (regex.test(this.seekInput)) return;
            let keywords = [this.seekInput];
            this.info_content = wrapText(this.infoData.info_content, keywords);
        },

        // 回到顶部
        gotop() {
            goTopSmooth();
        },
    },
};
</script>
<style lang="scss" scoped>
.breadcrumb {
    height: 2.28rem;
    line-height: 2.28rem;
    padding-left: 1.43rem;
    font-size: 0.75rem;
    color: #666666;
    background: #e8f4ff;
    border-bottom: 1px solid #f6f6f6;
}

.title {
    font-weight: 700;
    font-size: 1.25rem;
    color: #333333;
    line-height: 1.5;
    width: 89%;
    margin: 0 auto;
    padding-top: 1rem;
}

.info {
    width: 92%;
    margin: 1rem auto 0;
    background: #f3f9ff;
    border-radius: 10px;
    padding: 1rem 1.21rem;
    .info-item {
        display: flex;
        margin-bottom: 0.34rem;
        line-height: 1.5;
        font-weight: 400;
        font-size: 0.75rem;
        color: #3c6c9c;
        .label {
            min-width: 3.8rem;
        }
    }
}

.notice {
    background: #fffbf6;
    width: 92%;
    margin: 0.68rem auto 0;
    border-radius: 10px;
    padding: 1rem 1.21rem;
    font-size: 0.75rem;
    color: #4f3f2b;
    line-height: 1.25rem;
    .notice-title {
        font-weight: 700;
        margin-bottom: 0.2rem;
    }
}

.info_content {
    width: 90%;
    margin: 1rem auto 0;
    &::v-deep em {
        color: #ffffff !important;
        background: #f56c6c;
    }
    &::v-deep img {
        width: 100%;
        margin: 0 auto;
    }
    &::v-deep a {
        text-decoration: underline;
    }
}

.shoucang {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #d8d8d8;
    background-color: #ffffff;
    .but {
        width: 8.75rem;
        height: 2.5rem;
        line-height: 2.5rem;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0.93rem;
        color: #333333;
        background: #fdfdfd;
        border-radius: 2.5rem;
        border: 1px solid #dcdcdc;
        &:active {
            opacity: 0.8;
        }
    }
    .but-active {
        border-color: #ffcd90;
        background-color: #fff8ef;
    }
    .icon {
        padding-right: 0.3rem;
    }
}
</style>
